<template>
	<view class="cart-list">
		<template v-for="(item, index) in cartList">
			<view class="cart-item" v-if="isShowAddBuy || (!isShowAddBuy && item.isRelasionSale !== '2')" :key="item.productId + index">
				<img class="cart-item-left" :src="item.img" alt="">
				<view class="cart-item-right">
					<view class="up">
						<view class="name-mark">
							<view class="name">{{item.productName}}</view>
							<template v-if="item.isRelasionSale === '2'">
								<view class="mark">加价购</view>
							</template>
							<template v-else-if="item.couponId">
								<view class="mark">产品券</view>
							</template>
							<template v-else>
								<view class="mark" v-if="item.salePrice === item.specialPrice">特价</view>
							</template>
						</view>
						
						<template v-if="item.productRequire">
							<view class="details">{{item.productRequire}}</view>
						</template>
						<template v-if="item.desc">
							<template v-for="xItem in item.desc.split(';')">
								<view class="details" :key="xItem">{{xItem}}</view>
							</template>
						</template>
						
					</view>
					<view class="under">
						<view class="price" v-if="!item.couponId">
							<view class="sale">￥{{item.salePrice}}</view>
							<view class="origin" v-if="item.salePrice < item.orinPrice">￥{{item.orinPrice}}</view>
						</view>
						<view class="price" v-else>
							<view class="sale">￥{{Number(((item.addPrice || 0) + item.specialPrice).toFixed(2))}}</view>
							<view class="origin">￥{{item.orinPrice}}</view>
						</view>
						<template v-if="!onlyRead">
							<template v-if="item.couponId">
								<stepper :max="1" :min="min" :confirm="confirm" :cartInfo="item" :cartIndex="index"></stepper>
							</template>
							<template v-else>
								<stepper :min="min" :confirm="confirm" :cartInfo="item" :cartIndex="index"></stepper>					
							</template>
						</template>
						<template v-else>
							<view class="onlyread-num">× <text>{{item.productCount}}</text></view>
						</template>
					</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	import stepper from "../stepper/stepper.vue"
	export default {
		name: 'CartList',
		components: {
			stepper
		},
		props: {
			// 是否只读
			onlyRead: {
				type: Boolean,
				default () {
					return false;
				}
			},
			
			// 是否确认页
			confirm: {
				type: Boolean,
				default () {
					return false;
				}
			},

			// 最小
			min: {
				type: Number
			},

			// 是否显示加价购商品再购物车中
			isShowAddBuy: {
				type: Boolean,
				default () {
					return false;
				}
			}
		},
		data() {
			return {

			};
		},
		computed: {
			cartList() {
				return this.$store.state.cartList
			}
		},
		watch: {

		},
		mounted() {

		},
		methods: {

		}
	};
</script>

<style lang="less" scoped>
	@import "~@/common/styles/common.less";

	.cart-list {
		width: 100%;
		padding: 20rpx 0;
	}

	.cart-item {
		width: 100%;
		padding: 20rpx;
		display: flex;
		align-items: center;
		background: #fff;
	}

	.cart-item-left {
		width: 140rpx;
		height: 140rpx;
		border-radius: 10rpx;
		overflow: hidden;
		box-shadow: 0 0 8rpx 2rpx rgba(0, 0, 0, .1);
	}

	.cart-item-right {
		width: calc(100% - 140rpx);
		min-height: 140rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		font-size: 28rpx;
		padding-left: 20rpx;

		.name-mark {
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			.name {
				display: inline-block;
				font-size: 28rpx;
				font-weight: bold;
			}

			.mark {
				display: inline-block;
				padding: 6rpx 18rpx;
				line-height: 1;
				font-size: 22rpx;
				border-radius: 8rpx;
				background: fade(@assist, 20%);
				color: @assist;
				letter-spacing: 4rpx;
				transform: scale(.8);
			}
		}

		.details {
			font-size: 22rpx;
			color: #aaa;
		}

		.under {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.price {
				display: flex;
				align-items: flex-end;

				.sale {
					font-size: 32rpx;
					font-weight: bold;
				}

				.origin {
					margin-left: 10rpx;
					font-weight: 22rpx;
					transform-origin: left bottom;
					transform: scale(.8);
					color: #666;
					text-decoration: line-through;
				}
			}
		}

		.onlyread-num {
			text {
				font-size: 36rpx;
			}
		}
	}
</style>
